package entities

import (
	commonEntities "gitee.com/igolang/imoney/internal/common/entities"
	"time"
)

type NoticePageListReq struct {
	PageListReq
	NoticeTitle string `json:"noticeTitle" form:"noticeTitle"`
	CreateBy    string `json:"createBy" form:"createBy"`
	NoticeType  string `json:"noticeType" form:"noticeType"`
}

type ConfigPageListReq struct {
	PageListReq
	ConfigName string `json:"configName" form:"configName"`
	ConfigKey  string `json:"configKey" form:"configKey"`
	ConfigType string `json:"configType" form:"configType"`
}

type DictPageListReq struct {
	PageListReq
	DictName string `json:"dictName" form:"dictName"`
	DictType string `json:"dictType" form:"dictType"`
}

type DictDataPageListReq struct {
	PageListReq
	DictType  string `json:"dictType" form:"dictType"`
	DictLabel string `json:"dictLabel" form:"dictLabel"`
}

type PostPageListReq struct {
	PageListReq
	PostCode string `json:"postCode" form:"postCode"`
	PostName string `json:"postName" form:"postName"`
}

type OperLogPageListReq struct {
	PageListReq
	Title        string `json:"title" form:"title"`
	OperName     string `json:"operName" form:"operName"`
	BusinessType string `json:"businessType" form:"businessType"`
}

type LogininforPageListReq struct {
	PageListReq
	Ipaddr   string `json:"ipaddr" form:"ipaddr"`
	UserName string `json:"userName" form:"userName"`
}

type PageListReq struct {
	commonEntities.PageListReq
	Status    string    `json:"status" form:"status"`
	BeginTime string    `json:"params[beginTime]" form:"params[beginTime]"`
	EndTime   string    `json:"params[endTime]" form:"params[endTime]"`
	BT        time.Time `json:"-" form:"-"`
	ET        time.Time `json:"-" form:"-"`
}

func (p *PageListReq) Page() {
	if p.PageSize < 1 {
		p.PageSize = 10
	}

	if p.PageNum < 1 {
		p.PageNum = 1
	}

	p.Offset = (p.PageNum - 1) * p.PageSize
	if p.BeginTime != "" && p.EndTime != "" {
		p.BT, _ = time.ParseInLocation(time.DateTime, p.BeginTime+" 00:00:00", time.Local)
		p.ET, _ = time.ParseInLocation(time.DateTime, p.EndTime+" 23:59:59", time.Local)
	}
}
